package com.ayf.payment.game.api.service;

import com.alibaba.fastjson.JSONObject;
import com.ayf.payment.game.api.dto.*;
import com.ayf.payment.game.api.dto.criteria.*;
import com.ayf.payment.game.api.dto.getaway.GameRechargeGetWayDTO;
import com.ayf.payment.game.api.dto.platform.MerchantSettleDTO;
import com.ayf.payment.game.api.entity.Order;
import com.ayf.payment.game.api.type.OrderStatus;
import com.ayf.payment.game.api.utils.CommonResult;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.MapKey;
import org.springframework.transaction.annotation.Transactional;

import java.beans.Transient;
import java.util.List;
import java.util.Map;

public interface OrderService {
    /**
     * 充值订单添加
     *
     * @param orderCriteria
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    Map<String, Object> insertOrder(OrderCriteria orderCriteria) throws Exception;

    /**
     * 根据订单号获取订单
     *
     * @param merchantOrderNo
     * @return
     */
    Order selectByMerchantOrderNo(String merchantOrderNo);

    /**
     * 通过order 获取充值详情
     *
     * @param orderCriteria
     */
    GameRechargeGetWayDTO getOrderDetails(OrderCriteria orderCriteria);

    void update(Order order);

    /**
     * 通过网关充值到游戏中
     *
     * @param order
     */
    CommonResult orderToGetWay(Order order);

    /**
     * 查询处理中的订单
     *
     * @return
     */
    List<OrderAndMerchantDTO> selectProcessingOrder(OrderStatus orderStatus, long time);

    /**
     * 查询总条数
     *
     * @param order
     * @return
     */
    int selectCount(Order order);

    /**
     * 延时查询总条数
     *
     * @param order
     * @return
     */
    int selectCountAlterTime(Order order, long time);

    /**
     * 更改订单状态
     *
     * @param order
     * @return
     */
    @Transactional
    boolean changeOrderStatus(Order order);

    /**
     * 更改订单状态 成功订单后金额处理
     *
     * @param order
     * @return
     */

    void changeOrderStatusAndMerchantAccount(Order order, JSONObject data);


    /**
     * 更改脚本生成状态
     *
     * @param order
     * @return
     */
    @Transactional
    void updateScriptStatus(Order order);

    /**
     * 查询订单信息
     *
     * @param orderNo
     * @return
     */
    OrderDTO selectOrderByOrderNo(String orderNo);

    /**
     * 条件查询订单列表
     *
     * @param criteria
     * @return
     */
    List<OrderDTO> selectByDTO(OrderSelectCriteria criteria);

    /**
     * 分页查询出充值的所有账号信息
     *
     * @param reissueOrderDTO
     * @return
     */
    PageInfo<ReissueOrderDTO> selectRechargeNumbers(ReissueOrderDTO reissueOrderDTO);

    /**
     * 查询出符合条件的订单
     *
     * @param order
     * @return
     */
    List<Order> selectOrders(Order order);

    /**
     * 订单详情查询
     *
     * @param criteria
     * @return
     */
    ChargeOrderResponseDTO selectOrderList(OrderInfoCriteria criteria);

    /**
     * 订单查询
     *
     * @param criteria
     * @return
     */
    List<OrderInfoDTO> orderList(OrderInfoCriteria criteria);

    /**
     * 商户结算统计
     * 结算日期
     *
     * @param settleDate
     * @return
     */
    List<MerchantSettleDTO> merchantSettleByOrderCount(Integer orderGenerateTimeIndexEnd, Integer orderGenerateTimeIndexStrat, String settleDate, Short settleCycle);

    /**
     *  商户结算统计 统计代理商户代理费所得
     * 结算日期
     *
     * @param settleDate
     * @return
     */
    List<MerchantSettleDTO> merchantSettleByOrderCountProxy(Integer orderGenerateTimeIndexEnd, Integer orderGenerateTimeIndexStrat, String settleDate, Short settleCycle);

    /**
     * 查询商户收入汇总信息
     *
     * @param cri
     * @return
     */
    Map<Integer, Map<String, Object>> selectSumAmount(OrderInfoCriteria cri);

    /**
     * 查询代理商收入汇总信息
     *
     * @param cri
     * @return
     */
    @MapKey("proxy_id")
    Map<Integer, Map<String, Object>> selectSumProxyIncome(OrderInfoCriteria cri);

    /**
     * 查询汇总信息
     *
     * @param cri
     * @return
     */
    ChargeOrderResponseDTO selectSumAmountAndFee(OrderInfoCriteria cri);

    /**
     * 充值统计
     *
     * @param statistics
     * @return
     */
    StatisticsPageDTO topUpStatistics(StatisticsCriteria statistics);

    /**
     * 充值渠道结算统计
     *
     * @param statistics
     * @return
     */
    List<ChannelStatisticsDTO> channelStatistic(StatisticsCriteria statistics);

    List<PartitionStatisticsDTO> selectPartitionChargeSuccessDetailList(PartitionStatisticsCriteria criteria);

    /**
     * 支付后订单处理
     * @param order
     * @param dataObject
     */
    void paymentOrder(Order order, JSONObject dataObject);

    /**
     * 根据商户ID 和定单日期修改 为以加入结算单状态
     * @param merchantId
     * @param orderDate
     */
    void changeOrderIsSettleByDate(Integer merchantId, String orderDate);

    /**
     * 清理订单信息
     *
     * @param clean
     * @return
     */
    @Transient
    boolean cleanOrderAndSettle(CleanCriteria clean);

    /**
     * 结算金额手续费计算
     * @param order
     * @param merchantConfigDTO
     */
    void settleRateCount(Order order, MerchantConfigDTO merchantConfigDTO);

    void changeOrderIsSettle(String settleDate);

    /**
     * 重试发送脚本生成
     * @param merchantOrderNos
     * @return
     */
    CommonResult retryOrders(String[] merchantOrderNos);

    /**
     * 重试发送查看订单状态
     * @param merchantOrderNo
     * @return
     */
    CommonResult checkPayOrder(String merchantOrderNo);

    /**
     * 订时更改订单状态
     *
     * @param
     * @return
     */
    @Transactional
    void updateOrderStatus(String merchantOrderNo, long placeTime);
 /**
     * 查询推广员订单
     *
     * @param criteria
     * @return
     */
    List<OrderInfoDTO> selectSonOrderList(OrderInfoCriteria criteria);

    /**
     * 查询推销员汇总信息
     *
     * @param cri
     * @return
     */
    ChargeOrderResponseDTO selectSumSonAmount(OrderInfoCriteria cri);

    ChargeOrderResponseDTO partitionStatisticSum(StatisticsCriteria statistics);

    /**
     * 修正订单并发送脚本生成
     * @param
     * @return
     */
    CommonResult correctOrder(String merchantOrderNo,String ip);

    List<OrderInfoDTO> todayLastOrderList(OrderInfoCriteria orderCriteria);

    CommonResult deleteOrders(String[] merchantOrderNos);

    CommonResult updateOrderInfo(OrderCriteria criteria);

    OrderInfoDTO playerQueryOrderNo(String merchantOrderNo);

    void saveOrder(Order order);
}






